﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script src="~/Scripts/vue.js"></script>
    <link href="~/Content/ElementUI/element-ui.css" rel="stylesheet" />
    <script src="~/Scripts/ElementUI/element-ui.js"></script>
    <script src="~/Scripts/axios.js"></script>
</head>
<body>
    <div id="app">
        <!--表单  -->
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="航班号">
                <el-input v-model="formInline.flightNo" placeholder="航班号"></el-input>
            </el-form-item>
            <el-form-item label="是否有餐食">
                <el-select v-model="formInline.meals" placeholder="请选择">
                    <el-option label="无" value="无"></el-option>
                    <el-option label="小食" value="小食"></el-option>
                    <el-option label="正餐" value="正餐"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="出发机场">
                <el-select v-model="formInline.departureAirportId" placeholder="请选择">
                    <el-option label="---请选择---" value=""></el-option>
                    <el-option v-for="item in typeList " :label="item.airportName" :value="item.aId"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" v-on:click="onSubmit">查询</el-button>
                <el-button type="success" v-on:click="onAdd">添加</el-button>
            </el-form-item>
        </el-form>
        <!-- 表格 -->
        <template>
            <el-table :data="tableData" border style="width: 100%">
                <el-table-column prop="flightNo" label="航班号" width="180">
                </el-table-column>
                <el-table-column prop="arriveAirportType" label="出发机场" width="180">
                </el-table-column>
                <el-table-column prop="departureAirportType" label="落地机场" width="180">
                </el-table-column>
                <el-table-column prop="departureTime" label="出发时间" width="180">
                </el-table-column>
                <el-table-column prop="arriveTime" label="落地时间机场" width="180">
                </el-table-column>
                <el-table-column prop="price" label="价格" width="180">
                </el-table-column>
                <el-table-column prop="meals" label="是否有正餐" width="180">
                </el-table-column>
                <el-table-column width="180">
                    <el-button size="mini" v-on:click="Edit" type="primary">修改</el-button>
                    <el-button size="mini" type="danger">删除</el-button>
                </el-table-column>
            </el-table>
        </template>
        <!--分页-->
        <el-pagination background
                       v-on:size-change="handleSizeChange"
                       v-on:current-change="handleCurrentChange"
                       :current-page="page"
                       :page-sizes="[5, 10, 15, 20]"
                       :page-size="limit"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="count">
        </el-pagination>
        <!--添加对话框-->

        <el-dialog title="提示" :visible.sync="AdddialogVisible">
            @*添加的表单*@
            <el-form :model="addForm">
                <el-form-item label="航班号:">
                    <el-input style="width:50%" v-model="addForm.flightNo"></el-input>
                </el-form-item>

                <el-form-item label="出发机场">
                    <el-select v-model="addForm.departureAirport" placeholder="请选择">
                        <el-option label="---请选择---" value=""></el-option>
                        <el-option v-for="item in typeList " :label="item.airportName" :value="item.aId"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="到达机场">
                    <el-select v-model="addForm.arriveAirport" placeholder="请选择">
                        <el-option label="---请选择---" value=""></el-option>
                        <el-option v-for="item in typeList " :label="item.airportName" :value="item.aId"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="起飞时间">
                    <el-date-picker v-model="addForm.departureTime" type="datetime" placeholder="选择日期时间"> </el-date-picker>
                </el-form-item>

                <el-form-item label="下机时间">
                    <el-date-picker v-model="addForm.arriveTime" type="datetime" placeholder="选择日期时间"> </el-date-picker>
                </el-form-item>

                <el-form-item label="是否有餐食:">
                    <el-input style="width:50%" v-model="addForm.meals"></el-input>
                </el-form-item>

                <el-form-item label="价格:">
                    <el-input style="width:50%" v-model="addForm.price"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button v-on:click="AdddialogVisible = false">取 消</el-button>
                <el-button type="primary" v-on:click="AddDel">确 定</el-button>
            </span>
        </el-dialog>
        <!--编辑对话框-->
        <el-dialog title="提示" :visible.sync="EditdialogVisible">
            <span>这是一段信息</span>
            <span slot="footer" class="dialog-footer">
                <el-button v-on:click="EditdialogVisible = false">取 消</el-button>
                <el-button type="primary" v-on:click="EditdialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
    <script type="text/javascript">
        var app = new Vue({
            //挂载绑定id
            el: '#app',
            //数据储存
            data: {
                typeList: [],
                formInline: {
                    flightNo: '',
                    meals: '',
                    departureAirport: ''
                },
                tableData: [{
                }],
                page: 1,
                limit: 5,
                count: 0,
                //添加窗口显示隐藏
                AdddialogVisible: false,
                addForm: {
                    flightNo: '',
                    departureAirport: '',
                    arriveAirport: '',
                    departureTime: '',
                    arriveTime: '',
                    meals: '',
                    price: ''
                },
                //编辑窗口显示隐藏
                EditdialogVisible: false
            },
            //动作方法
            methods: {
                onSubmit: function () {
                    let a = this;
                    axios.post('/Home/GetPageIist',
                        {
                            page: a.page,
                            limit: a.limit,
                            flightNo: a.formInline.flightNo,
                            meals: a.formInline.meals,
                            departureAirport: a.formInline.departureAirport
                        })
                        .then(function (res) {
                            //console.log(res);
                            a.tableData = res.data.data;
                            a.count = res.data.count
                        }).catch(
                            function (res) {
                                alert("出现未知错误");
                            })
                },
                handleSizeChange(val) {
                    this.limit = val;
                    this.onSubmit();
                },
                handleCurrentChange(val) {
                    this.page = val;
                    this.onSubmit();
                },
                //开启关闭编辑对话框
                Edit: function () {
                    this.EditdialogVisible = !this.EditdialogVisible;
                },
                //开启关闭添加对话框
                onAdd: function () {
                    this.AdddialogVisible = !this.AdddialogVisible;
                },
                //添加请求
                AddDel: function () {
                    let a = this;
                    axios.post('/Home/PostAdd', a.addForm)
                        .then(function (res) {
                            if (res.data.code) {
                                a.AdddialogVisible = false;
                                a.onSubmit();
                                this.$message(res.data.msg);
                            } else {
                                this.$message(res.data.msg);
                            }
                        }).catch(function (err) { })
                }

            },
            //html生成之前
            created: function () {
                let a = this;
                axios.get('/Home/GetTypeList')
                    .then(function (res) {
                        //console.log(res);
                        a.typeList = res.data;
                    }).catch(
                        function (res) {

                        });
                a.onSubmit();
            }
        })
    </script>
</body>
</html>